<html>

<head>
    <include file="public@head" title="管理员-系统设置"/>
</head>

<body class="layui-layout-admin">
<include file="public@header"/>
<include file="public@side"/>
<div class="layui-body">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a href="{:url('tdadmin/index/index')}">主页</a>
        <a href="{:url('tdadmin/admin/index')}">系统设置</a>
        <a><cite>管理员</cite></a>
    </div>
    <div class="layui-fluid pdt10">
        <div class="layui-card">
            <div class="layui-card-header">
                管理员
                <a href="{:url('add')}" class="layui-btn fr"><i class="layui-icon">&#xe61f;</i>添加管理员</a>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide table-center" id="lists" lay-filter="lists"></table>

                <script type="text/html" id="barLists">
                    {{# if(d.id != 1){ }}
                    <a class="layui-btn layui-btn-sm" href="{:url('edit')}?id={{d.id}}"><i
                            class="layui-icon layui-icon-list"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete"><i
                            class="layui-icon layui-icon-delete"></i>删除</a>
                    {{# } }}
                </script>
            </div>
        </div>
    </div>
</div>
<include file="public@scripts"/>
<script>
    var table = layui.table;

    table.render({
        elem: '#lists',
        even: true,
        url: "{:url('getAdmins')}",
        cols: [[
            {field: 'id', title: 'ID', align: 'center', width: 60}
            , {field: 'admin_login', title: '登录账号',}
            , {field: 'nick_name', title: '昵称'}
            , {field: 'mobile', title: '电话'}
            , {field: 'title', title: '角色'}
            , {field: 'last_login_ip', title: '上次登录IP'}
            , {field: 'last_login_time', title: '上次登录时间', width: 180}
            , {field: 'status', title: '状态', width: 80}
            , {fixed: 'right', title: '操作', align: 'center', width: 180, toolbar: '#barLists'}
        ]]
    });

    //监听单元格编辑
    table.on('edit(lists)', function (obj) {
        var value = obj.value,
            data = obj.data,
            field = obj.field;
        $.ajax({
            type: "post",
            url: "{:url('updateField')}?id=" + data.id + "&field=" + field + "&value=" + value,
        });
    });
    table.on('tool(lists)', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        var tr = obj.tr;
        if (layEvent === 'delete') {
            layer.confirm('您将彻底删除【' + data.title + '】！', function (index) {
                obj.del();
                layer.close(index);
                $.ajax({
                    type: "post",
                    data: {id: data.id},
                    url: "{:url('delAdmin')}",
                    success: function (result) {

                        if (result.code == 1) {
                            layer.msg(result.msg, {icon: 6, time: 1000}, function (index) {
                                layer.close(index);
                                window.location.reload();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 5, time: 800}, function (index) {
                                layer.close(index);
                            });
                            return false;
                        }
                    }
                });
            });
        }
    });
</script>
</body>

</html>
